package com.hengfoxwolf.jetpackdemo.defineview
import android.content.Context
import android.util.AttributeSet
import android.widget.ScrollView
import com.hengfoxwolf.jetpackdemo.R

class ExtraScrollView constructor(context: Context, attributeSet: AttributeSet? = null) :
    ScrollView(context, attributeSet) {

    private var extraHeight = 0F

    init {
        context.obtainStyledAttributes(attributeSet, R.styleable.ExtraScrollView).apply {
            extraHeight = getDimension(R.styleable.ExtraScrollView_extraHeight,0F)
            recycle()
        }
    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        val bottomTabHeight = extraHeight.toInt()
        val height = MeasureSpec.getSize(heightMeasureSpec) - bottomTabHeight
        super.onMeasure(
            widthMeasureSpec,
            MeasureSpec.makeMeasureSpec(height, heightMeasureSpec)
        )
    }

}